#ifndef _DB_THREAD_HPP_20120610
#define _DB_THREAD_HPP_20120610

#include "listbuffer.hpp"

#include "db_queue.hpp"
#include "thread.hpp"

#include "sql_util.hpp"

using namespace mina;
using namespace mina::thread;

class DBThread : public Thread
{
	public :
		typedef int (DBThread::*PROCESS_FUN)(SqlUtil::RecordSet & record, DBResponse & response);
		typedef std::map<int, PROCESS_FUN> ProcMap;
		typedef ProcMap::iterator ProcMap_Iter;

	public :
		DBThread();
		~DBThread();

		virtual void run();

	public :
		int process(int op_type, SqlUtil::RecordSet & record, DBResponse & response);

		int insert_proc(SqlUtil::RecordSet & record, DBResponse & response);
		int delete_proc(SqlUtil::RecordSet & record, DBResponse & response);
		int update_proc(SqlUtil::RecordSet & record, DBResponse & response);
		int select_proc(SqlUtil::RecordSet & record, DBResponse & response);
		int count_proc(SqlUtil::RecordSet & record, DBResponse & response);

	public :
		SqlUtil::DataBase *  _database;

		ProcMap              _proc_map;

		MemoryPool *         _memory_pool;
		PoolBufferAlloc *    _buffer_alloc;

		ListBuffer *         _list_buffer;

		DECL_LOGGER(logger);
};

#endif

